package com.watsons.csd_process.callback;

import com.alibaba.fastjson.JSONObject;
import com.watsons.csd_process.service.DindService;
import com.watsons.csd_process.service.SentryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 处理sentry回调
 */
@RestController
@Slf4j
@RequestMapping(value = "sentry")
public class SentryCallBack {

    @Autowired
    private DindService dindService;

    @Autowired
    private SentryService sentryService;

    @RequestMapping(value = "issue")
    public Object issue(@RequestBody JSONObject object, @RequestParam String project) {
        log.info("项目:{}", project);
        log.info("issue:{}", object);
        dindService.sendDingNotify(project, sentryService.Sentry2Issue(object));
        return "OK";
    }

}
